<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">



    <title>查看用户</title>
</head>
<body>
<jsp:include page="/incloud/header.jsp" />

<div class="d-flex align-items-stretch">
    <!-- Sidebar Navigation-->
    <jsp:include page="/incloud/sidebar.jsp" />
    <!-- Sidebar Navigation end-->
    <div class="page-content">
        <div class="page-header">
            <div class="container-fluid">
                <h2 class="h5 no-margin-bottom">用户列表</h2>
            </div>
        </div>
        <section class="no-padding-bottom">
            <div class="title">
                <form class="form-inline" action="/user/findPage" method="get">
                    <input type="hidden" name="currPage" value="1">
                    <div class="form-group">
                        <label for="inlineFormInput" class="sr-only">Name</label>
                        <input id="inlineFormInput" name="searchVal" value="${searchVal}" type="text" placeholder="按名字查找" class="mr-sm-3 form-control">
                    </div>
                    <div class="form-group">
                        <input type="submit" value="查询" class="btn btn-primary">
                    </div>
                </form>

            </div>


            <div class="table-responsive">
                <table class="table">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>姓名</th>
                        <th>真实姓名</th>
                        <th>性别</th>
                        <th>年龄</th>
                        <th>简介</th>
                        <th>操作</th>
                        <th>加关注</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${pageData.data}" var="user">





                    <tr>
                        <th scope="row">${user.id}</th>
                        <td>${user.username}</td>
                        <td>${user.realName}</td>
                        <td>
                            <c:if test="${user.gender==1}">男</c:if>
                            <c:if test="${user.gender==0}">女</c:if>
                        </td>
                        <td>${user.age}</td>
                        <td>${user.info}</td>
                        <td>
                            <input type="submit" value="详细信息" onclick="userDetail(${user.id},${user.isSecret})" class="btn-xs btn-primary userDetail">
                        </td>
            
                        <td>
            
                            <input type="checkbox" value="" onclick="addFocus(${user.id},event)"
                                   class="checkbox-template" ${focusIdList.contains(user.id)?'checked':''}>
            
                        </td>
                    </tr>
<%--                    <tr>--%>
<%--                        <th scope="row">2</th>--%>
<%--                        <td>小标</td>--%>
<%--                        <td>1-表示男</td>--%>
<%--                        <td>20</td>--%>
<%--                        <td>我很帅</td>--%>
<%--                        <td>--%>
<%--                            <input type="submit" value="详细信息" id="userDetail" class="btn-xs btn-primary userDetail">--%>
<%--                        </td>--%>
<%--                        <td>--%>
<%--                            <input type="checkbox" value="" class="checkbox-template">--%>
<%--                        </td>--%>
<%--                    </tr>--%>
                    </c:forEach>
                    </tbody>
                </table>
            
                <nav class="text-center" aria-label="Page navigation">
                    <ul class="pagination">
                        <li>
                            <a href="javascript:" aria-label="Previous" onclick="pre()">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <c:forEach begin="1" end="${pageData.totalPage}" varStatus="row">
                        <li ><a ${pageData.currPage==row.count?"style='color: green;'":''}
                                href="/user/findPage?currPage=${row.count}&searchVal=${searchVal}">${row.count}</a></li>
                        </c:forEach>

                        <li>
                            <a href="javascript:" aria-label="Next" onclick="next()">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </ul>
                </nav>
            </div>
        </section>

        <jsp:include page="/incloud/footer.jsp" />
    </div>
</div>

<!-- JavaScript files-->


<script type="text/javascript">


    /**
     * 加关注/取消关注
     * @param userId
     */
    function addFocus(userId,event){


        if('${loginUser.id}'==userId){

            //阻止该事件的默认行为
            event.preventDefault()

            layer.msg("不能关注自己！")
            return
        }

        $.post("/user/addFocus?userId="+userId,function (flag){

            if(flag =='1'){
                layer.msg("关注成功！")
            }else {
                layer.msg("取消关注！")
            }
        });

    }



    function userDetail(userId,isSecret){

        if(isSecret!='1'){
            layer.msg("对方私密了！")
            return
        }

        location.href = "/user/userDetail?userId="+userId+"&flag=detail"

    }



    /**
     * 上一页
     */

    function pre() {
        if(${pageData.currPage-1==0}){

            layer.msg("已经到顶啦!");
            return;
        }

        window.location.href = "/user/findPage?currPage=${pageData.currPage-1}&searchVal=${searchVal}"

    }

    /**
     * 下一页
     */
    function next(){
        if(${pageData.currPage+1>pageData.totalPage}){

            layer.msg("已经到底啦！");
            return;
        }

        window.location.href = "/user/findPage?currPage=${pageData.currPage+1}&searchVal=${searchVal}"

    }






    $(function(){
		
		//用户列表，查看详情，通过class名字userDetail来找
		$("#userDetail").click(function () {
		    console.log("你点击了用户详情");
		    window.location.href = '/html/user_detail.jsp'
		});
		
		// $(".table").find("input[type='checkbox']").on("click",function () {
		//     if($(this).prop("checked")){
		//         layer.msg("关注成功")
		//     }else{
		//         layer.msg("取关成功")
		//
		//     }
		//
		// })
		
	})
	
</script>
</body>
</html>